/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.buzz.workjcdj.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.buzz.workjcdj.entity.Workjcdj;
import com.jeeplus.modules.buzz.workjcdj.mapper.WorkjcdjMapper;
import com.jeeplus.modules.buzz.workjcdj.entity.Workjcdjentry;
import com.jeeplus.modules.buzz.workjcdj.mapper.WorkjcdjentryMapper;

/**
 * 检查登记Service
 * @author 陈
 * @version 2025-07-14
 */
@Service
@Transactional(readOnly = true)
public class WorkjcdjService extends CrudService<WorkjcdjMapper, Workjcdj> {

	@Autowired
	private WorkjcdjentryMapper workjcdjentryMapper;
	
	public Workjcdj get(String id) {
		Workjcdj workjcdj = super.get(id);
		workjcdj.setWorkjcdjentryList(workjcdjentryMapper.findList(new Workjcdjentry(workjcdj)));
		return workjcdj;
	}
	
	public List<Workjcdj> findList(Workjcdj workjcdj) {
		return super.findList(workjcdj);
	}
	
	public Page<Workjcdj> findPage(Page<Workjcdj> page, Workjcdj workjcdj) {
		return super.findPage(page, workjcdj);
	}
	
	@Transactional(readOnly = false)
	public void save(Workjcdj workjcdj) {
		super.save(workjcdj);
		for (Workjcdjentry workjcdjentry : workjcdj.getWorkjcdjentryList()){
			if (workjcdjentry.getId() == null){
				continue;
			}
			if (Workjcdjentry.DEL_FLAG_NORMAL.equals(workjcdjentry.getDelFlag())){
				if (StringUtils.isBlank(workjcdjentry.getId())){
					workjcdjentry.setInteryid(workjcdj);
					workjcdjentry.preInsert();
					workjcdjentryMapper.insert(workjcdjentry);
				}else{
					workjcdjentry.preUpdate();
					workjcdjentryMapper.update(workjcdjentry);
				}
			}else{
				workjcdjentryMapper.delete(workjcdjentry);
			}
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(Workjcdj workjcdj) {
		super.delete(workjcdj);
		workjcdjentryMapper.delete(new Workjcdjentry(workjcdj));
	}
	
}